<template>
  <div class="uploadApk">
    <Upload ref="upload"
            :max-size='fileMaxSize'
            :on-exceeded-size="showError"
            :on-success="handleSuccess"
            :action="fileUploadAction">
      <input name="token"
             type="hidden"
             value="<upload_token>">
      <Button icon="ios-cloud-upload-outline"
              v-if="url">重新上传</Button>
      <Button icon="ios-cloud-upload-outline"
              v-else>上传文件</Button>
    </Upload>
    <!--<div v-if="file !== null"><Button type="text" @click="upload" :loading="loadingStatus">{{ loadingStatus ? '正在上传' : '上传' }}</Button></div>-->
  </div>
</template>

<script>
export default {
  name: 'uploadApk',
  props: ['fileUploadAction', 'url'],
  data () {
    return {
      fileMaxSize: 2048 * 100,
      file: null,
      loadingStatus: false
    }
  },
  methods: {
    handleUpload (file) {
      this.file = file;
      return false;
    },
    upload () {
      this.$refs.upload.post(this.file);
    },
    handleSuccess (response, file, fileList) { // 文件上传回调 上传成功后删除待上传文件
      this.$emit('setUrl', file)
    },
    showError (file, fileList) {
      this.$Notice.warning({
        title: '文件大小超限',
        desc: '文件  ' + file.name + ' 太大，上传文件大小不能超过200M.'
      });
    }
  }
}
</script>

<style lang="scss" type="text/scss" rel="stylesheet/scss">
.uploadApk {
}
</style>
